<?php
/**
 * Created by PhpStorm.
 * User: SSNSK
 * Date: 2017-09-18
 * Time: 10:45
 */
var_dump($_POST);
//$_POST['pricerule']='all';//所有日期
//$_POST['pricerule']='week';//按星期
//$_POST['pricerule']='month';//按号数\

//$startTimeStr=strtotime($_POST['starttime']);
//$endTimeStr=strtotime($_POST['endtime']);
//$startTime=date('Y-m-d',$startTimeStr);
//echo '$startTime'.$startTime;
//
//$nextTime =mktime(0,0,0,date('m',$startTimeStr),date('d',$startTimeStr)+1,date('Y',$startTimeStr));
//echo '$endTime'.date('Y-m-d',$endTimeStr);
//echo '</br>$nextTime'.date('Y-m-d',$nextTime);
//echo '日期差'.$dayCount=round(($endTimeStr-$startTimeStr)/(60*60*24));
//setPriceByAall();
//setPriceline();
function setPriceline(){

    $startTimeStr=strtotime($_POST['starttime']);
    $endTimeStr=strtotime($_POST['endtime']);


    $maxMonth=array('01','03','05','07','08','10','12');
    $minMonth=array('04','06','09','11');

    $skuArr=$_POST['propgroup'];
    $skuCount=count($skuArr);

    $priceArr=$_POST['price'];
    $number=$_POST['number'];
    $priceRule=$_POST['pricerule'];
    if ($priceRule=='all'){
        $dayCount=round(($endTimeStr-$startTimeStr)/(60*60*24));
        $t=0;
        while($skuCount>$t++){
//        echo 't=>'.$t;
            $d=0;
            $data['skuid']=$skuArr[$t-1];
            $data['price']=$priceArr[$t-1];
            $data['store']=$number;
            while($dayCount>$d++){
//            echo 'd=>'.$d;
                $nextTime =mktime(0,0,0,date('m',$startTimeStr),date('d',$startTimeStr)+$d,date('Y',$startTimeStr));
//            echo '$nextTime=>'.date('Y-m-d',$nextTime).'</br>';
                $data['pdate']=date('Y-m-d',$nextTime);

            var_dump($data);
            }

        }
    }elseif ($priceRule=='week'){
        $weekArr=$_POST['weekval'];

        $weekCount=count($weekArr);
//        $dayCount=round(($endTimeStr-$startTimeStr)/(60*60*24));

        $s=0;
        while($skuCount>$s++) {
//        echo 't=>'.$t;
            $data['skuid'] = $skuArr[$s - 1];
            $data['price'] = $priceArr[$s - 1];
            $data['store'] = $number;
            $t = 0;
            while ($weekCount > $t++) {
//        echo 't=>'.$t;
                $Week = $weekArr[$t - 1];
                $nextWeek = strtotime("-1 week", strtotime($Week));
                $w = 0;
                echo '</br>星期' . $Week . '</br>';
                while ($endTimeStr > $nextWeek) {

                    $nextWeek = strtotime("+" . $w++ . " week", strtotime($Week));
                    if ($nextWeek > $endTimeStr) break;
                    $data['pdate'] = date('Y-m-d', $nextWeek);

                    var_dump($data);
                }

            }
        }

    }elseif ($priceRule=='month'){
        $numberArr=$_POST['monthval'];
        $numberCount=count($numberArr);
        $t=0;
        $count=0;
        while($skuCount>$t++) {
//        echo 't=>'.$t;
            $data['skuid'] = $skuArr[$t - 1];
            $data['price'] = $priceArr[$t - 1];
            $data['store'] = $number;

            $nextMonth=strtotime("+0 months",$startTimeStr);
            $m=0;
            while ($endTimeStr > $nextMonth) {
                $nextMonth = strtotime("+" . $m++ . "months", $startTimeStr);
                $n = 0;
                while ($numberCount > $n++) {
                    $Number = $numberArr[$n - 1];
                    $nm = date('m', $nextMonth);
                    $ny = date('Y', $nextMonth);

//                处理小月份31号问题
                    if (in_array($nm, $minMonth) && $Number == 31) {
                        continue;
                    } elseif ($nm == 02) {
                        if ($Number > 29) continue;
                        if ($Number == 29 && !($ny % 4 == 0 && ($ny % 100 != 0 || $ny % 400 == 0))) {
                            continue;
                        }

                    }
                    $nextTime = mktime(0, 0, 0, $nm, $Number, $ny);

                    if ($nextTime < $startTimeStr || $nextTime > $endTimeStr) continue;
                    $data['pdate'] = date("Y-m-d", $nextTime);
                    echo $count++;
                    var_dump($data);

                }
            }
        }

    }


}

//setPricehotel();
//function setPricehotel(){
//
//    $startTimeStr=strtotime($_POST['starttime']);
//    $endTimeStr=strtotime($_POST['endtime']);
//    $dayCount=round(($endTimeStr-$startTimeStr)/(60*60*24));
//
//    $price=$_POST['price'];
//    $number=$_POST['number'];
//
//    $data['skuid']=1;
//    $data['price']=$price;
//    $data['store']=$number;
//    $d=0;
//    while($dayCount>$d++){
//        $nextTime =mktime(0,0,0,date('m',$startTimeStr),date('d',$startTimeStr)+$d,date('Y',$startTimeStr));
////            echo '$nextTime=>'.date('Y-m-d',$nextTime).'</br>';
//        $data['pdate']=date('Y-m-d',$nextTime);
//        var_dump($data);
//    }
//
//}
$startTimeStr=strtotime($_POST['starttime']);
$endTimeStr=strtotime($_POST['endtime']);
//echo date("Y-m-d")."</br>";
//echo date("Y-m-d",strtotime("-1 months",$startTimeStr))."</br>";
//echo date("Y-m-d",strtotime("+0 months",$startTimeStr))."</br>";
//echo date("Y-m-d",strtotime("+1 months",$startTimeStr))."</br>";
//echo date("Y-m-d",strtotime("+6 week"))."</br>";
//setPriceSpot();
function setPriceSpot(){

    $startTimeStr=strtotime($_POST['starttime']);
    $endTimeStr=strtotime($_POST['endtime']);
    $priceRule=$_POST['pricerule'];

    $maxMonth=array('01','03','05','07','08','10','12');
    $minMonth=array('04','06','09','11');

    $price=$_POST['price'];
    $number=$_POST['number'];

    $data['skuid']=1;
    $data['price']=$price;
    $data['store']=$number;
    if ($priceRule=='all'){
        $dayCount=round(($endTimeStr-$startTimeStr)/(60*60*24));
        $d=0;
        while($dayCount>$d++){
            $nextTime =mktime(0,0,0,date('m',$startTimeStr),date('d',$startTimeStr)+$d,date('Y',$startTimeStr));
//            echo '$nextTime=>'.date('Y-m-d',$nextTime).'</br>';
            $data['pdate']=date('Y-m-d',$nextTime);
            var_dump($data);
        }
    }elseif ($priceRule=='week'){
        $weekArr=$_POST['weekval'];

        $weekCount=count($weekArr);
//        $dayCount=round(($endTimeStr-$startTimeStr)/(60*60*24));

        $t=0;
        while($weekCount>$t++){
//        echo 't=>'.$t;
            $Week=$weekArr[$t-1];
            $nextWeek =strtotime("-1 week",strtotime($Week));
            $w=0;
            echo '</br>星期'.$Week.'</br>';
            while($endTimeStr>$nextWeek){

                $nextWeek =strtotime("+".$w++." week",strtotime($Week));
                if ($nextWeek>$endTimeStr) break;
                $data['pdate']=date('Y-m-d',$nextWeek);

                var_dump($data);
            }

        }

    }elseif ($priceRule=='month'){
        $numberArr=$_POST['monthval'];
        $numberCount=count($numberArr);
        $nextMonth=strtotime("+0 months",$startTimeStr);
        $m=0;
        while($endTimeStr>$nextMonth){
            $nextMonth=strtotime("+".$m++."months",$startTimeStr);
            $n=0;
            while($numberCount>$n++){
                $Number=$numberArr[$n-1];
                $nm=date('m',$nextMonth);
                $ny=date('Y',$nextMonth);

//                处理小月份31号问题
                if (in_array($nm,$minMonth) && $Number==31){
                    continue;
                }elseif ($nm==02){
                    if ($Number>29) continue;
                    if ($Number==29 && !($ny%4==0 && ($ny%100!=0 || $ny%400==0))) {
                        continue;
                    }

                }
                $nextTime =mktime(0,0,0,$nm,$Number,$ny);

                if ($nextTime<$startTimeStr || $nextTime>$endTimeStr) continue;
                $data['pdate']=date("Y-m-d",$nextTime);
                var_dump($data);

            }
        }

    }


}


//按所有日期存储数据
//while(){
//
//}

//一周之后:  strtotime("+1 week") ;
//一周之前:  strtotime("-1 week") ;
//一月之后:  strtotime("+1 months") ;
//一天之后:  strtotime("+1 days") ;
//30秒之后 strtotime( " +30 seconds " );
//  20分钟之后 strtotime( " +20 minutes " );
//  12个小时之后 strtotime( " +12 hours " );




